//
//  ItemCollectionViewCell.m
//  MKUI
//
//  Created by sushangjin on 2020/6/5.
//Copyright © 2020 sushangjin. All rights reserved.
//

#import "ItemCVCell.h"

@interface ItemCVCell ()

@end

@implementation ItemCVCell
- (id)initWithFrame:(CGRect)frame{
	if (self=[super initWithFrame:frame]) {
       //
        self.button = [[MKUIFlowLayoutButton alloc] initWithContentStyle:MKUIFlowLayoutButtonContentStyleVertical];
        [self.button setImage:[UIImage mk_imageWithUIColor:[UIColor redColor]] forState:UIControlStateNormal];
        self.button.imageSize = CGSizeMake(20, 20);
        self.button.contentInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        self.button.interitemSpacing = 5;
        [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button mk_setBackgroundColorForNormalAndHighlightedState:[UIColor lightGrayColor]];
        [self.button setTitle:@"Go" forState:UIControlStateNormal];
        [self.button mk_addClickActionBlock:^(ItemCVCell *self) {
            [self.collectionCellModel didClickSelf];
        } context:self];
        [self.contentView addSubview:self.button];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[self.button] constraintParam:MKUIFlowLayoutConstraintParam_H_C_C contentInsets:UIEdgeInsetsMake(5, 5, 5, 5) interitemSpacing:5];
	}
	return self;
}
- (void)customLayoutSubviews{
    [super customLayoutSubviews];
    CGRect bounds = self.contentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (void)customReloadCellModel{
	[super customReloadCellModel];
	Item *modelObject = self.collectionCellModel.modelValue;
    [self.button setTitle:modelObject.name forState:UIControlStateNormal];
}
- (CGSize)customSizeThatFits:(CGSize)size{
    CGSize s = [self.flowlayout sizeThatFits:CGSizeMake(99999999, 99999999) resizeItems:YES];
    return s;
}
@end
